package com.gnerv.battle.boot.framework.core.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Component
@AllArgsConstructor
public class AsyncInterceptor implements HandlerInterceptor {

    private AsyncHandlerInterceptorChain battleAsyncHandlerInterceptorChain;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        battleAsyncHandlerInterceptorChain.preHandle(request, response, handler);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        battleAsyncHandlerInterceptorChain.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        battleAsyncHandlerInterceptorChain.afterCompletion(request, response, handler, ex);
    }


}
